package chpt12;

import java.sql.*;

public class DBbasic2Cursor {
	public static void main(String[] args) {
		String url = "jdbc:mysql://127.0.0.1:3306/demoDB?serverTimezone=Asia/Chongqing";
		String userName = "root";
		String pwd = "root123";
		Connection con = null;
			try {
				con = DriverManager.getConnection(
						url, userName, pwd);
				Statement stmt = con.createStatement(
						ResultSet.TYPE_SCROLL_INSENSITIVE, 
						ResultSet.CONCUR_READ_ONLY);
			String sql = "select * from students";
			ResultSet rs = stmt.executeQuery(sql);
			rs.afterLast();
			while (rs.previous())
				System.out.println("id=" + rs.getInt(1) +
						"; 学号=" + rs.getString(2) +
						"; 姓名=" + rs.getString("name") + 
						"; GPA=" + rs.getDouble(4)+
						"; 生日="+rs.getDate(5));
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
}
